package com.Lixiaoqian.Gulangyu.location

import android.content.Context
import com.baidu.location.BDAbstractLocationListener
import com.baidu.location.BDLocation
import com.baidu.location.LocationClient
import com.baidu.location.LocationClientOption



/**
 * Created by huangzhibo on 2018-02-26.
 * mail:1043202454@qq.com
 */
class LocationClient(var context: Context) : ILocation {
    var mLocationClient: LocationClient = LocationClient(context)
    init {
        mLocationClient.registerLocationListener(object : BDAbstractLocationListener() {
            override fun onReceiveLocation(position: BDLocation?) {
                resultListenr.callPositionData(PositionBean(position?.latitude, position?.longitude,position?.direction,position?.radius))
            }
        })
        val option = LocationClientOption()

        option.locationMode = LocationClientOption.LocationMode.Hight_Accuracy

        option.setCoorType("bd09ll")

        option.setScanSpan(1000)

        option.isLocationNotify = true

        option.setWifiCacheTimeOut(5 * 60 * 1000)

        mLocationClient.locOption = option
    }

    override fun restorLoca() {
        mLocationClient.restart()
    }

    private lateinit var resultListenr: ILocation.LocationResult
    override fun setLocationResult(listener: ILocation.LocationResult) {
        resultListenr = listener
    }

    override fun startLoca() {
        mLocationClient.start()
    }

    override fun stopLoca() {
        mLocationClient.stop()
    }

}